package com.test.qnews.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.android.volley.toolbox.NetworkImageView;
import com.test.qnews.R;
import com.test.qnews.beans.QuestionBeans;
import com.test.qnews.volley.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 16/1/21.
 */
public class DetailsQuestionAdapter extends BaseAdapter {
    private List<QuestionBeans> data;
    private Context context;

    public DetailsQuestionAdapter(List<QuestionBeans> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Viewholder holder = new Viewholder();
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_details_question,null);
            holder.user_content = (TextView) convertView.findViewById(R.id.detail_user_content);
            holder.user_name = (TextView) convertView.findViewById(R.id.detail_user_name);
            holder.user_head_picUrl = (NetworkImageView) convertView.findViewById(R.id.detail_user_head_picUrl);
            holder.specia_list_content = (TextView) convertView.findViewById(R.id.detail_specia_list_content);
            holder.specia_list_name = (TextView) convertView.findViewById(R.id.detail_specia_list_name);
            holder.specia_list_head_picUrl = (NetworkImageView) convertView.findViewById(R.id.detail_specia_list_head_picUrl);
            convertView.setTag(holder);
        }else{
            holder = (Viewholder) convertView.getTag();
        }
        Log.d("DetailsQuestionAdapter", data.get(position).getDetail_user_name());
        Log.d("DetailsQuestionAdapter", data.get(position).getDetail_user_head_picUrl());
        holder.user_name.setText(data.get(position).getDetail_user_name());
        holder.user_content.setText(data.get(position).getDetail_user_content());
        holder.specia_list_name.setText(data.get(position).getDetail_specia_list_name());
        holder.specia_list_content.setText(data.get(position).getDetail_specia_list_content());
        VolleySingleton.getInstance().loadImage(holder.specia_list_head_picUrl, data.get(position).getDetail_specia_list_head_picUrl());
        if (null!= data.get(position).getDetail_user_head_picUrl()) {
            VolleySingleton.getInstance().loadImage(holder.user_head_picUrl, data.get(position).getDetail_user_head_picUrl());

        }
        return convertView;
    }



    //创建缓存类
      private class Viewholder{
        private TextView user_content;
        private TextView user_name;
        private NetworkImageView user_head_picUrl;
        private TextView specia_list_content;
        private TextView specia_list_name;
        private NetworkImageView specia_list_head_picUrl;
    }
}

